<?php

/**
 * KTDAdventure form.
 *
 * @package    s-test
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class KTDAdventureForm extends BaseKTDAdventureForm
{
  public function configure()
  {
      //On emboite le formulaire d'action en plus du formulaire de création d'une aventure
      $this->embedForm("first_action", new KTDActionForm());

      unset($this['udpated_at'], $this['region_id'], $this['sum'], $this['is_finished'], $this['started_at']);

      $this->setWidget("title", new sfWidgetFormInput(array("label" => "Titre de l'aventure")));
      $this->setValidator("title", new sfValidatorString(array("required" => true)));

      $this->widgetSchema->setNameFormat("ktd_adventure[%s]");
      
  }
  public function  updateObject($values = null) {
        parent::updateObject($values);
        $this->manageFirstAction();
        return $this->object;
    }
  public function manageFirstAction(){

        //créeons la première action...
        $values = $this->getValues();
        $act = new KTDAction();
        $act->fromArray($values['first_action']);
        $act->setCharacterId($this->getOption("character_id"));
        $act->setKTDAdventure($this->getObject());



        //on remplit le formulaire inclus en entier
        $this->embeddedForms["first_action"] = new KTDActionForm($act);
  }
}
class BackendKTDAdventureForm extends KTDAdventureForm{
  public function configure()
  {
      unset($this['udpated_at'], $this['started_at']);
      $this->setWidget("title", new sfWidgetFormInput(array("label" => "Titre")));
      $this->setValidator("title", new sfValidatorString(array("required" => true)));
      
      $this->setWidget("sum", new sfWidgetFormTextarea(array("label" => "Résumé")));
      $this->setValidator("sum", new sfValidatorString(array("required" => false)));

      $this->setWidget("is_finished", new sfWidgetFormInputCheckbox(array("label" => "Terminée ?")));
      $this->widgetSchema->setNameFormat("ktd_adventure[%s]");

  }
  public function manageFirstAction(){
      
  }
}